R/2_visualization.r
radial_cheem_tour.RdCreate a linked plotlyof the global data-
and attribution- spaces. Typically consumed directly by shiny app.
radial_cheem_tour(
cheem_ls,
basis,
manip_var,
primary_obs = NULL,
comparison_obs = NULL,
do_add_pcp_segments = TRUE,
pcp_shape = c(142, 124, 3),
angle = 0.15,
row_index = NULL,
inc_var_nms = NULL,
do_center_frame = TRUE,
do_add_residual = FALSE
)
radial_cheem_tour_subplots(
cheem_ls,
basis,
manip_var,
primary_obs = NULL,
comparison_obs = NULL,
do_add_pcp_segments = TRUE,
pcp_shape = c(142, 124, 3),
angle = 0.15,
row_index = NULL,
inc_var_nms = NULL,
do_center_frame = TRUE
)A return from cheem_ls(), a list of data frames.
A 1D projection basis, typically a return of
basis_attr_df().
The , number of the manipulation variable.
The rownumber of the primary observation. Its local attribution becomes the 1d projection basis, and the point it highlighted as a dashed line. Defaults to NULL, no primary observation highlighted.
The rownumber of the comparison observation. Point is highlighted as a dotted line. Defaults to NULL, no comparison observation highlighted.
Logical, whether or not to add parallel coordinate line segments to the basis display.
The number of the shape character to add. Expects
142, 124, 3 '|' for plotly and gganimate or '+' in either respectively.
Defaults to 142, '|' for plotly.
The step size between interpolated frames, in radians. Defaults to .15.
Numeric index of selected observations. Defaults to TRUE; 1:n.
A vector of the names of the variables to include in the projection.
Whether or not to scale by standard deviations away from the mean within each frame or not. Defaults to TRUE, helping to keep the animation centered.
Whether of not to add a facet with a fixed y on residual. Doing so may cause issues with animation. Defaults to FALSE.
ggtour (ggplot2 object with frame info) animation frames of a
radial tour manipulating the contribution of a selected tour. Animated with
spinifex::animate_* functions.
Other cheem consumers:
global_view(),
run_app()
library(cheem)
library(spinifex)
## Classification:
X <- penguins_na.rm[, 1:4]
clas <- penguins_na.rm$species
Y <- as.integer(clas)
rf_fit <- default_rf(X, Y)
## Long runtime for full datasets or complex models:
shap_df <- attr_df_treeshap(rf_fit, X, noisy = FALSE)
this_ls <- cheem_ls(X, Y, class = clas,
model = rf_fit,
attr_df = shap_df)
bas <- basis_attr_df(shap_df, rownum = 1)
ggt <- radial_cheem_tour(this_ls, basis = bas, manip_var = 1,
primary_obs = 1, comparison_obs = 2)
#> devMessage: phi_start > pi / 2; phi_start <- phi_start - pi & phi_max <- -phi_max
#> devMessage: manual_tour: is_mv_x_neg == TRUE; phi_start <- pi / 2L - abs(phi_start); phi_path <- rev(phi_path)
if (FALSE) {
animate_plotly(ggt)
if(FALSE) ## or animate with gganimate
animate_gganimate(ggt) #, render = gganimate::av_renderer())
## Regression:
dat <- amesHousing2018_NorthAmes
X <- dat[, 1:9]
Y <- log(dat$SalePrice)
clas <- dat$SubclassMS
rf_fit <- default_rf(X, Y)
## Long runtime for full datasets or complex models:
shap_df <- attr_df_treeshap(rf_fit, X, noisy = FALSE)
this_ls <- cheem_ls(X, Y, class = clas,
model = rf_fit,
attr_df = shap_df)
bas <- basis_attr_df(shap_df, rownum = 1)
ggt <- radial_cheem_tour(this_ls, basis = bas, manip_var = 1)
animate_plotly(ggt)
if(FALSE) ## or animate with gganimate
animate_gganimate(ggt, render = gganimate::av_renderer())
}
## Experimental radial tour made from plotly::subplots rather than facets
ggt <- radial_cheem_tour_subplots(this_ls, basis = bas, manip_var = 1)
#> devMessage: phi_start > pi / 2; phi_start <- phi_start - pi & phi_max <- -phi_max
#> devMessage: manual_tour: is_mv_x_neg == TRUE; phi_start <- pi / 2L - abs(phi_start); phi_path <- rev(phi_path)
#> devMessage: manual_tour: is_mv_x_neg == TRUE; phi_start <- pi / 2L - abs(phi_start); phi_path <- rev(phi_path)
#> Warning: Aspect ratios aren't yet implemented, but you can manually set a suitable height/width
#> Warning: Aspect ratios aren't yet implemented, but you can manually set a suitable height/width
animate_plotly(ggt)